﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadProps
{
    public class Composer
    {
        LinkedList<IComposable> items = new LinkedList<IComposable>();

        public Composition Compose()
        {
            return new Composition(items);
        }

        public Composer AddFirst(IComposable instance)
        {
            items.AddFirst(instance.ThrowIfNull("instance"));
            return this;
        }

        public Composer AddFirst<T>() where T : IComposable, new()
        {
            return AddFirst(new T());
        }

        public Composer AddLast(IComposable instance)
        {
            items.AddLast(instance.ThrowIfNull("instance"));
            return this;
        }

        public Composer AddLast<T>() where T : IComposable, new()
        {
            return AddLast(new T());
        }

        public static Composer StandardBuild()
        {
            var me = new Composer();

            me.AddFirst<Templating.StandardSuggestor>();
            me.AddFirst<Templating.UIHintSuggestor>();

            me.AddLast<Definition.DefaultMetadata>();
            me.AddLast<Definition.CreateMetadataFromAttributes>();
            me.AddLast<Definition.ComponentModelMetadata>();

            me.AddLast<Validation.DataAnnotationsValidator>();

            return me;
        }
    }
}
